package com.sunwayhorizo.health.hl7.persistent;

import com.sunwayhorizo.health.hl7.factories.*;
import com.sunwayhorizo.health.hl7.persistent.pk.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.persistence.*;

@Entity
@AttributeOverrides({
/*
 * @AttributeOverride(name = "systemId", column = @Column(name = "ACT_ID")),
 * 
 * @AttributeOverride(name = "versionNum", column = @Column(name =
 * "ACT_VERSION_NUM")),
 */
@AttributeOverride(name = "codeEtsId", column = @Column(name = "ACT_CODE_ETS_ID")) })
@TableGenerator(name = "Act_IdGenerator", table = "Rim_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn", pkColumnValue = "Act_Id")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PARTITION_BY_CLASS", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("RimCoreActs")
// @NamedQuery(name = "Act.findAll", query = "select o from Act o")
@Table(name = "RIM_CORE_ACTS")
@IdClass(RimCoreActsPK.class)
public class RimCoreActs extends InfrastructureRoot implements Serializable
{
    // 系统做的工作
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "Act_IdGenerator")
    @Column(name = "ACT_ID", nullable = false)
    private Long actId;
    @Id
    @Column(name = "ACT_VERSION_NUM", nullable = false)
    private Long actVersionNum;
    // ControlAct 维护Entities、roles、Acts、ActRelations、Prtcptns、RoleLink
    @OneToMany(mappedBy = "controlAct", fetch = FetchType.LAZY, targetEntity = RimCoreEntities.class, cascade = CascadeType.ALL)
    private List<RimCoreEntities> controlActEntitiesList = new ArrayList<RimCoreEntities>();

    //
    @OneToMany(mappedBy = "controlAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreActs> controlActActsList = new ArrayList<RimCoreActs>();

    @OneToMany(mappedBy = "controlAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoles> controlActRolesList = new ArrayList<RimCoreRoles>();

    @OneToMany(mappedBy = "controlAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreActPrtcptns> controlActPrtcptnsList = new ArrayList<RimCoreActPrtcptns>();

    @OneToMany(mappedBy = "controlAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreActRelations> controlActRelationsList = new ArrayList<RimCoreActRelations>();

    @OneToMany(mappedBy = "controlAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoleLink> controlActRoleLinkList = new ArrayList<RimCoreRoleLink>();

    // Act 维护Ii、CdSets、Prtcptns、Relations
    @OneToMany(mappedBy = "rimCoreActs", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreActIi> actsIiList = new ArrayList<RimCoreActIi>();

    @OneToMany(mappedBy = "rimCoreActs", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreActCdSets> actCdSetsList = new ArrayList<RimCoreActCdSets>();

    @OneToMany(mappedBy = "participationAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreActPrtcptns> prtcptnsActList = new ArrayList<RimCoreActPrtcptns>();

    @OneToMany(mappedBy = "sourceAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreActRelations> sourceActRelationsList = new ArrayList<RimCoreActRelations>();

    @OneToMany(mappedBy = "targetAct", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreActRelations> targetActRelationsList = new ArrayList<RimCoreActRelations>();

    @ManyToOne
    @JoinColumn(name = "DC_ROOT_ID", referencedColumnName = "ROOT_ID")
    private RimCoreRootMaster rootMaster;

    // @ManyToOne(cascade = CascadeType.ALL)
    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "TEXT_ED_ID", referencedColumnName = "ED_ID")
    private RimCoreEds rimCoreEdsTextEdId = new RimCoreEds();
    
    
    // activityTime
    @Column(name = "ACTIVITY_DATE_GTS_TXT")
    protected String activityDateGtsTxt;
    @Column(name = "ACTIVITY_END_DATE_TS")
    protected Timestamp activityEndDateTs;
    @Column(name = "ACTIVITY_START_DATE_TS")
    protected Timestamp activityStartDateTs;


    /**
     * //@ManyToOne(cascade = CascadeType.ALL)
     * 
     * @OneToOne(cascade = CascadeType.ALL)
     * @JoinColumn(name = "OB_VALUE_ED_ID", referencedColumnName = "ED_ID")
     *                  private RimCoreEds rimCoreEdsObValueEdId = new
     *                  RimCoreEds();
     */
    protected RimCoreActs()
    {
        Long i = new Long(1);
        actVersionNum = i;

    }


    protected RimCoreActs(ReferenceModifier referencemodifier)
    {

        super(referencemodifier);
        Long i = new Long(1);
        actVersionNum = i;
    }


    // 系统做的工作
    /*
     * protected Long getActId() { return actId; }
     * 
     * protected void setActId(Long actId) { this.actId = actId; }
     * 
     * protected Long getActVersionNum() { return actVersionNum; }
     * 
     * protected void setActVersionNum(Long actVersionNum) { this.actVersionNum
     * = actVersionNum; }
     */
    // ActCdSets

    public void setActCdSetsList(List<RimCoreActCdSets> actCdSetsIiList)
    {
        this.actCdSetsList = actCdSetsIiList;
    }


    public List<RimCoreActCdSets> getActCdSetsList()
    {
        return actCdSetsList;
    }


    public RimCoreActCdSets addActCdSets(RimCoreActCdSets actCdSets)
    {
        getActCdSetsList().add(actCdSets);
        actCdSets.setRimCoreActs(this);
        return actCdSets;
    }


    public RimCoreActCdSets removeActCdSets(RimCoreActCdSets actCdSets)
    {
        getActCdSetsList().remove(actCdSets);
        actCdSets.setRimCoreActs(null);
        return actCdSets;
    }


    // ControlAct 维护 Entities
    public void setControlActEntitiesList(List<RimCoreEntities> controlActEntitiesList)
    {
        this.controlActEntitiesList = controlActEntitiesList;
    }


    public List<RimCoreEntities> getControlActEntitiesList()
    {
        return controlActEntitiesList;
    }


    public RimCoreEntities addEntity(RimCoreEntities entity)
    {
        getControlActEntitiesList().add(entity);
        entity.setControlAct(this);
        return entity;
    }


    public RimCoreEntities removeEntity(RimCoreEntities entity)
    {
        getControlActEntitiesList().remove(entity);
        entity.setControlAct(null);
        return entity;
    }


    // ControlAct 维护 Acts
    public void setControlActActsList(List<RimCoreActs> controlActActsList)
    {
        this.controlActActsList = controlActActsList;
    }


    public List<RimCoreActs> getControlActActsList()
    {
        return controlActActsList;
    }


    public RimCoreActs addControlActAct(RimCoreActs acts)
    {
        getControlActActsList().add(acts);
        acts.setControlAct(this);
        return acts;
    }


    public RimCoreActs removeControlActAct(RimCoreActs acts)
    {
        getControlActActsList().remove(acts);
        acts.setControlAct(null);
        return acts;
    }


    // ControlAct 维护 Roles
    public void setControlActRolesList(List<RimCoreRoles> controlActRolesList)
    {
        this.controlActRolesList = controlActRolesList;
    }


    public List<RimCoreRoles> getControlActRolesList()
    {
        return controlActRolesList;
    }


    public RimCoreRoles addControlActRole(RimCoreRoles roles)
    {
        getControlActRolesList().add(roles);
        roles.setControlAct(this);
        return roles;
    }


    protected RimCoreRoles removeControlActRole(RimCoreRoles roles)
    {
        getControlActRolesList().remove(roles);
        roles.setControlAct(null);
        return roles;
    }


    // ControlAct 维护 Participations
    public void setControlActPrtcptnsList(List<RimCoreActPrtcptns> controlActPrtcptnsList)
    {
        this.controlActPrtcptnsList = controlActPrtcptnsList;
    }


    public List<? super RimCoreActPrtcptns> getControlActPrtcptnsList()
    {
        return controlActPrtcptnsList;
    }


    // ControlAct 维护ActRelation
    private void setControlActRelationsList(List<RimCoreActRelations> controlActRelationsList)
    {
        this.controlActRelationsList = controlActRelationsList;
    }


    private List<? super RimCoreActRelations> getControlActRelationsList()
    {
        return controlActRelationsList;
    }


    protected RimCoreActRelations addControlActRelation(RimCoreActRelations actRelations)
    {
        getControlActRelationsList().add(actRelations);
        actRelations.setControlAct(this);
        return actRelations;
    }


    protected RimCoreActRelations removeControlActRelation(RimCoreActRelations actRelations)
    {
        getControlActRelationsList().remove(actRelations);
        actRelations.setControlAct(null);
        return actRelations;
    }


    // ControlAct 维护RimCoreRoleLink
    public List<RimCoreRoleLink> getControlActRoleLinkList()
    {
        return controlActRoleLinkList;
    }


    public void setControlActRoleLinkList(List<RimCoreRoleLink> controlActRoleLinkList)
    {
        this.controlActRoleLinkList = controlActRoleLinkList;
    }


    public RimCoreRoleLink addControlActRoleLink(RimCoreRoleLink roleLink)
    {
        getControlActRoleLinkList().add(roleLink);
        roleLink.setControlAct(this);
        return roleLink;
    }


    public RimCoreRoleLink removeControlActRoleLink(RimCoreRoleLink roleLink)
    {
        getControlActRoleLinkList().remove(roleLink);
        roleLink.setControlAct(null);
        return roleLink;
    }


    // Act 维护 Ii
    protected void setActsIiList(List<RimCoreActIi> actsIiList)
    {
        this.actsIiList = actsIiList;
    }


    /**
     * 此方法需要设置成受保护的protected，现在开放成public是因为业务代码没调整，还在用
     * 
     * @return
     */
    public List<RimCoreActIi> getActsIiList()
    {
        return actsIiList;
    }


    protected RimCoreActIi addActIi(RimCoreActIi actIi)
    {
        getActsIiList().add(actIi);
        actIi.setRimCoreActs(this);
        return actIi;
    }


    protected RimCoreActIi removeActIi(RimCoreActIi actIi)
    {
        getActsIiList().remove(actIi);
        actIi.setRimCoreActs(null);
        return actIi;
    }


    /**
     * Act 维护 Participations
     * 
     * @param prtcptnsActList
     */
    protected void setPrtcptnsActList(List<RimCoreActPrtcptns> prtcptnsActList)
    {
        this.prtcptnsActList = prtcptnsActList;
    }


    /**
     * 此方法应设置成protected，没有调整是因为业务代码中有直接调用getPrtcptnsActList的方法，后期调整
     * 
     * @return
     */
    public List<? extends RimCoreActPrtcptns> getPrtcptnsActList()
    {
        return prtcptnsActList;
    }


    // SourceAct 维护 ActRelation
    protected void setSourceActRelationsList(List<RimCoreActRelations> sourceActRelationsList)
    {
        this.sourceActRelationsList = sourceActRelationsList;
    }


    public List<? extends RimCoreActRelations> getSourceActRelationsList()
    {
        return sourceActRelationsList;
    }


    // TargetAct 维护 ActRelation
    protected void setTargetActRelationsList(List<RimCoreActRelations> targetActRelationsList)
    {
        this.targetActRelationsList = targetActRelationsList;
    }


    public List<? extends RimCoreActRelations> getTargetActRelationsList()
    {
        return targetActRelationsList;
    }


    /*
     * protected void setMasterCatalogId(Long masterCatalogId) {
     * this.masterCatalogId = masterCatalogId; }
     * 
     * protected Long getMasterCatalogId() { return masterCatalogId; }
     * 
     * 
     * protected McEntries getMcEntries() { return mcEntries; }
     * 
     * protected void setMcEntries(McEntries mcEntries) { this.mcEntries =
     * mcEntries; }
     */

    protected void setRimCoreEdsTextEdId(RimCoreEds rimCoreEdsTextEdId)
    {
        this.rimCoreEdsTextEdId = rimCoreEdsTextEdId;
    }


    protected RimCoreEds getRimCoreEdsTextEdId()
    {
        return rimCoreEdsTextEdId;
    }


    public void setRootMaster(RimCoreRootMaster rootMaster)
    {
        this.rootMaster = rootMaster;
    }


    public RimCoreRootMaster getRootMaster()
    {
        return rootMaster;
    }


    public void setActId(Long actId)
    {
        this.actId = actId;
    }


    public Long getActId()
    {
        return actId;
    }


    public void setActVersionNum(Long actVersionNum)
    {
        this.actVersionNum = actVersionNum;
    }


    public Long getActVersionNum()
    {
        return actVersionNum;
    }


    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((actId == null) ? 0 : actId.hashCode());
        return result;
    }


    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        RimCoreActs other = (RimCoreActs) obj;
        if (actId == null)
        {
            if (other.actId != null)
                return false;
        }
        else if (!actId.equals(other.actId))
            return false;
        return true;
    }

}
